#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QMouseEvent>
#include <QWheelEvent>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    total=0;

    //显示的告诉Qt追踪鼠标的移动
    this->setMouseTracking(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    //鼠标移动事件触发太频繁，占用资源，Qt不会调用这个事件，除非使用setMouseTracking显示的告诉Qt
    qDebug()<<event->x()<<","<<event->y()<<Qt::endl;
}

void Widget::wheelEvent(QWheelEvent *event)
{
    //qDebug()<<event->angleDelta();
    qDebug()<<event->delta();
    total+=event->delta();
    qDebug()<<"total:"<<total;
}
